<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>角色管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">增加角色</button>
    </div>
</script>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

</script>


<script src="../layui/layui.js" charset="utf-8"></script>
<script src="../js/jquery-3.4.1.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url:'/logisticsPost/selectAll'
            ,toolbar: '#toolbarDemo'
            ,title: '用户数据表'
            ,totalRow: true
            ,cols: [[
                {type: 'numbers',title:"序号",align:"center",width:80, fixed: 'left'}
                ,{field:'postId', title:'角色编号',align:"center", width:150, fixed: 'left'}
                ,{field:'postName', title:'角色名称',align:"center", width:150, edit: 'text'}
                ,{field:'sectionName', title:'所属部门', align:"center",width:180,sort:true, edit: 'text'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
            ]]
            ,page: true
        });

        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData'://新增角色
                    var data = checkStatus.data;
                    layer.open({
                        type: 2,
                        area: ['750px', '600px'],
                        fixed: false, //不固定
                        maxmin: true,
                        content: '/wjc/postUpdate.html'
                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                layer.msg('查看操作');
            } else if (layEvent === 'del') {

                layer.confirm('真的删除行么', function (index) {
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);//关闭弹窗
                    //向服务端发送删除指令
                    let url = "/logisticsPost/delete";
                    let data1 = {postId: data.postId}
                    $.get(url, data1, function (resp) {
                            layer.msg(resp.mes);
                    }, "json");
                });
            } else if (layEvent === 'edit') {//编辑
                layer.open({
                    type: 2,
                    area: ['750px', '600px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: '/wjc/postUpdate.html?postId=' + data.postId
                });
            }
        });

    });
</script>

</body>
</html>